package cn.rocksolid.sport.assist.config;

import java.util.Map;

import org.apache.commons.collections4.MapUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import cn.rocksolid.sport.common.Constant.SmsProviderType;
import cn.rocksolid.sport.common.error.RSE;
import cn.rocksolid.sport.common.error.RockSolidException;

@ConfigurationProperties(prefix = "rocksolid")
@Component
public class SmsConfig {

  protected Map<SmsProviderType, Map<String, Map<String, String>>> smsConfigs;

  public Map<SmsProviderType, Map<String, Map<String, String>>> getSmsConfigs() {
    return smsConfigs;
  }

  public void setSmsConfigs(Map<SmsProviderType, Map<String, Map<String, String>>> smsConfigs) {
    if (MapUtils.isNotEmpty(smsConfigs)) {
      for (Map.Entry<SmsProviderType, Map<String, Map<String, String>>> configEntry : smsConfigs.entrySet()) {
        if (!configEntry.getValue().containsKey(ConfigConst.DEFAULT_CONF)) {
          throw new RockSolidException(RSE.MISS_SMSP_DC);
        }
      }
    }
    this.smsConfigs = smsConfigs;
  }
}
